import {
  createRouter,
  createWebHashHistory,
  type RouteLocationNormalized,
} from "vue-router";
// import NProgress from "@/utils/progress.ts";
import Layout from "@/components/Layout/index.vue";
import Home from "@/views/home/index.vue";
import Search from "@/views/search/index.vue";
import SchRes from "@/views/schRes/index.vue";
import Detail from "@/views/detail/index.vue";

const routes = [
  {
    path: "/",
    name: "Layout",
    component: Layout,
    children: [
      {
        path: "/",
        redirect: () => {
          return { path: "/home" };
        },
      },
      {
        path: "/home",
        name: "Home",
        component: Home,
      },
      {
        path: "/search",
        name: "Search",
        component: Search,
      },
      {
        path: "/schRes",
        name: "SchRes",
        component: SchRes,
      },
      {
        path: "/detail",
        name: "Detail",
        component: Detail,
      },
    ],
  },
];
// 路由
const router = createRouter({
  history: createWebHashHistory(),
  routes,
  scrollBehavior(_, _1, savedPosition) {
    if (savedPosition) {
      return savedPosition;
    } else {
      return { top: 0 };
    }
  },
});
export interface toRouteType extends RouteLocationNormalized {
  meta: {
    title?: string;
    noCache?: boolean;
  };
}

router.beforeEach((_to: toRouteType, _from, next) => {
  // NProgress.start();
  next();
});

router.afterEach(() => {
  // NProgress.done();
});
// 导出
export default router;
